package com.study.app;

import com.study.bean.Cat;
import com.study.bean.Mouse;
import com.study.config.SpringConfig4;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @desc:
 * @author: panxiyi
 * @date: 2023/5/15 9:58 上午
 */
public class App5 {
    // 使用上下文对象在容器初始化完毕后注入bean
    public static void main(String[] args) {
        AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(SpringConfig4.class);
        ctx.registerBean("tom", Cat.class, 0);
        ctx.registerBean("tom", Cat.class, 1);
        ctx.registerBean("tom", Cat.class, 2);

        ctx.register(Mouse.class);



        String[] beanDefinitionNames = ctx.getBeanDefinitionNames();
        for (String beanDefinitionName : beanDefinitionNames) {
            System.out.println(beanDefinitionName);
        }

        System.out.println("----------------");
        System.out.println(ctx.getBean("tom"));
        System.out.println(ctx.getBean(Cat.class));

    }
}
